var pageCount = 1;
function classOnload(a){
    console.log(a);

var Json = {
    pageSize:9,
    pageIndex:a
}
ajax.post(ajax.myUrl+"relax/relaxList",Json,function(result){
    console.log(result);
    response(result);
    // console.log(result.dataset.relaxList);
    var data = result.dataset.relaxList;
    var tbody = document.querySelector("tbody");
    for(var i=0;i<data.length;i++){
        var newtr = document.createElement("tr");
        newtr.innerHTML=`
        <td>${data[i].auditor}</td>
        <td>${data[i].relaxPri}</td>
        <td>${data[i].relaxReason}</td>
        <td>${data[i].createTime}</td>
        <td>${data[i].relaxDate}</td>
        <td>${data[i].relaxDuration}</td>
        <td>${data[i].status}</td>
        `;
        tbody.appendChild(newtr)
    }
    
})
}
//点击搜索实现按姓名搜索
var btn = document.querySelector(".search").querySelector("button");

btn.onclick = function(){
var inputs = document.querySelector(".search").querySelector("input");
   var Json2={
       userName:inputs.value,
       pageIndex:1,
       pageSize:10
   }
   ajax.post(ajax.myUrl+"relax/relaxList",Json2,function(result){
   console.log(result.dataset.relaxList);
   var data = result.dataset.relaxList;
   if(data.length==0){
       alert("该用户不存在,请重新输入");
   }
   var tbody = document.querySelector("tbody");
   for(var i=0;i<data.length;i++){
       tbody.innerHTML=`<tr>
                           <td>${data[i].userId}</td>
                           <td>${data[i].businessLocation}</td>
                           <td>${data[i].createTime}</td>
                           <td>${data[i].endTime}</td>
                           <td>${data[i].businessDuration}</td>
                           <td>${data[i].relaxDuration}</td>
                       </tr>`
   }
})
}
//点击申请，弹出模态框
//获取模态框
var goOut = document.getElementsByClassName("goOut")[0];
var addition = document.getElementsByClassName("addition")[0];
var apply = addition.getElementsByClassName("apply")[0];
apply.onclick = function(){
    goOut.style.display = "block";
}
var inputs = goOut.querySelectorAll("input");
var select = goOut.querySelector("select");
console.log(select.value)

//点击申请模态框中的确定或取消，模态框消失
var sure = document.getElementsByClassName("sure")[0];
sure.onclick = function(){
    var arrRest=[];
    goOut.style.display = "none";
    //sure确定点击后发送数据
    for(var i = 0; i<inputs.length;i++){
        arrRest[i]=inputs[i].value;
    }
    arrRest.push(select.value);
    console.log(arrRest)
    console.log(arrRest[1][8]+arrRest[1][9],arrRest[2][8]+arrRest[2][9])
    var startDay = Number(arrRest[1][8]+arrRest[1][9]);
    var endDay = Number(arrRest[2][8]+arrRest[2][9]);
    console.log(startDay,endDay)
    var num = endDay-startDay;//请假时长
    console.log(num);
    var  relaxPri = "";//老师或者学生身份标识
    if(select.value=="老师"){
        relaxPri=2
    }else if(select.value=="学生"){
        relaxPri=1
    }
    var Json2 = {
        relaxDate:arrRest[1],
        relaxReson:arrRest[3],
        userId:3, //用户id
        relaxDuration:num,//请假时长
        relaxPri: relaxPri,//1学生，2老师
        // auditor:"郭航" //审核人
    }
    ajax.post(ajax.myUrl+"relax/addRelax",Json2,function(result){
        console.log(result)
 })
    
}

var cancel = document.getElementsByClassName("cancel")[0];
cancel.onclick = function(){
    goOut.style.display = "none";
}
var dailyTime = document.getElementById("dailyTime");
var nowTime = new Date();
var year = nowTime.getFullYear();
var month = nowTime.getMonth()+1;
var day = nowTime.getDate();
var hour = nowTime.getHours();
var minutes = nowTime.getMinutes();
if(month<10){
    month="0"+month;
}
dailyTime.setAttribute("value",year+"-"+month+"-"+day);